package com.cskaoyan.shopping.controller.heheer;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.shopping.dal.persistence.PanelContentMapper;
import com.cskaoyan.shopping.dal.persistence.PanelMapper;
import com.cskaoyan.shopping.dto.CartProductDto;
import com.cskaoyan.shopping.dto.PanelDto;
import com.cskaoyan.shopping.form.CartRequest;
import com.cskaoyan.shopping.service.IHomeService;
import com.cskaoyan.shopping.service.IShoppingCartService;
import com.cskaoyan.shopping.service.IShoppingRecommendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author 1784549954@qq.com
 * @since 2022/12/02 21:14
 */
@RestController
public class ShoppingController {

    @Autowired
    IShoppingRecommendService iShoppingRecommendService;

    @Autowired
    IShoppingCartService iShoppingCartService;




    /**
     * 商品热门推荐接口完成
     *
     * @return com.cskaoyan.mall.commons.result.ResponseData
     * @author heheer
     * @since 2022/12/03 10:08
     */
    @GetMapping("/shopping/recommend")
    public ResponseData recommend() {
        PanelDto panelDto = iShoppingRecommendService.recommend();
        Set<PanelDto> panelDtos = new HashSet<>();
        panelDtos.add(panelDto);
        return new ResponseUtil<>().setData(panelDtos);
    }


    /**
     * 添加商品到购物车
     *
     * @param cartRequest
     * @return com.cskaoyan.mall.commons.result.ResponseData
     * @author heheer
     * @since 2022/12/03 13:45
     */
    @PostMapping("/shopping/carts")
    public ResponseData shoppingCarts(@RequestBody CartRequest cartRequest) {

        iShoppingCartService.postCarts(cartRequest);
        return new ResponseUtil<>().setData(null);
    }


    /**
     * 获取购物车列表
     *
     * @param request
     * @return com.cskaoyan.mall.commons.result.ResponseData
     * @author heheer
     * @since 2022/12/03 14:22
     */
    @GetMapping("/shopping/carts")
    public ResponseData getCarts(HttpServletRequest request) {
        List<CartProductDto> list = iShoppingCartService.getCsrts(request);
        return new ResponseUtil<>().setData(list);
    }


    /**
     * 更新购物车列表
     *
     * @param cartRequest
     * @return com.cskaoyan.mall.commons.result.ResponseData
     * @author heheer
     * @since 2022/12/03 14:22
     */
    @PutMapping("/shopping/carts")
    public ResponseData putCarts(@RequestBody CartRequest cartRequest) {
        iShoppingCartService.putCarts(cartRequest);
        return new ResponseUtil<>().setData(null);
    }


}
